找传奇、传世资源到传世资源站!

两个函数轻松实现txt文本读写

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

public static string Read_config_txt()
        {
            string config_txt_content = "";
            string exe_path = Application.ExecutablePath;
            int startIndex = exe_path.IndexOf("Debug"); 
            string temp_filebox_path = exe_path.Substring(0, startIndex);
            StreamReader sr = new StreamReader((temp_filebox_path "config.txt"), Encoding.UTF8); 
            string a_line_content = "";
            while ((a_line_content = sr.ReadLine()) != null)
            {
                config_txt_content = config_txt_content a_line_content;
                config_txt_content = config_txt_content.Replace("\t", "");
                config_txt_content = config_txt_content.Replace("\r\n", "");
                config_txt_content = config_txt_content.Replace(" ","");
            }
            sr.Close();
            return config_txt_content;
        }

        public static void Write_config_txt(string config_txt_content)
        {
            string exe_path = Application.ExecutablePath;
            int startIndex = exe_path.IndexOf("Debug"); 
            string temp_filebox_path = exe_path.Substring(0, startIndex);
            StreamWriter sw = File.CreateText(temp_filebox_path "config.txt"); //追加写入
            sw.Write(config_txt_content);
            sw.Flush();
            sw.Close();
        }

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复